package org.binglan.youziyuepai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.binglan.youziyuepai.entity.Occupation;
import org.binglan.youziyuepai.mapper.OccupationMapper;
import org.binglan.youziyuepai.service.OccupationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.n3r.idworker.Id;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 有关约拍职业表 服务实现类
 * </p>
 *
 * @author sanjin
 * @since 2019-04-09
 */
@Service
public class OccupationServiceImpl extends ServiceImpl<OccupationMapper, Occupation> implements OccupationService {

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public boolean isExistsIds(List<Integer> occupationIds) {
        QueryWrapper<Occupation> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",occupationIds);
        return occupationIds.size() == this.count(queryWrapper);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public String queryNameById(Integer occupationId) {
        Occupation occupation = new Occupation();
        occupation.setId(occupationId);
        return getOne(new QueryWrapper<>(occupation)).getOccupationName();
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<Occupation> queryAllOccupation() {
        List<Occupation> list = list(null);
        return list;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Occupation queryOccupationById(Integer occupationId) {
        if (occupationId == null)
            return null;
        Occupation occupation = new Occupation();
        occupation.setId(occupationId);
        return getOne(new QueryWrapper<>(occupation));
    }
}
